package swing.swing01;

import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;

public class border {
    JFrame fr=new JFrame("测试边框");

    public void init(){

        fr.setLayout(new GridLayout(2,4));

        // 创建BevelBorder
        Border bevelBorder=BorderFactory.createBevelBorder(BevelBorder.RAISED,Color.red,Color.green,Color.blue,Color.gray);
        fr.add(getJPanelWithBorder(bevelBorder,"BevelBorder"));

        //创建LineBorder
        Border lineBorder=BorderFactory.createLineBorder(Color.orange,10);
        fr.add(getJPanelWithBorder(lineBorder,"LineBorder"));

        //创建EmptyBorder
        Border emptyBorder=BorderFactory.createEmptyBorder(10,5,20,10);
        fr.add(getJPanelWithBorder(emptyBorder,"EmptyBorder"));

        // 创建EchtedBorder
        Border echtedBorder=BorderFactory.createEtchedBorder(EtchedBorder.RAISED,Color.red,Color.green);
        fr.add(getJPanelWithBorder(echtedBorder,"EchtedBorder"));

        // 创建TitledBorder
        TitledBorder titleBorder=new TitledBorder(new LineBorder(Color.orange,10),"测试标题",TitledBorder.LEFT,TitledBorder.BOTTOM,new Font("StSong",Font.BOLD,24),Color.blue);
        fr.add(getJPanelWithBorder(titleBorder,"TitledBorder"));

        // 创建MatteBorder
        MatteBorder matteBorder=new MatteBorder(10,5,20,10,Color.green);
        fr.add(getJPanelWithBorder(matteBorder,"MatteBorder"));

        // 创建CompoundBorder 组合边框
        CompoundBorder compoundBorder=new CompoundBorder(new LineBorder(Color.red,10),titleBorder); // new LineBorder(外边框,内边框);
        fr.add(getJPanelWithBorder(compoundBorder,"CompoundBorder"));


        fr.pack();
        fr.setVisible(true);
        fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }

    public JPanel getJPanelWithBorder(Border border,String content){
        JPanel jPanel = new JPanel();
        jPanel.add(new JLabel(content));

        // 设置边框
        jPanel.setBorder(border);

        return jPanel;
    }

    public static void main(String[] args){
        new border().init();
    }

}
